import { readFileSync } from "fs";
import path from "path";

/**
 * @function escapeHTML 转义html脚本 < > & " '
 * @param a -
 *            字符串
 */
function escapeHTML(a) {
  a = "" + a;
  return a
    .replace(/&/g, "&amp;")
    .replace(/</g, "&lt;")
    .replace(/>/g, "&gt;")
    .replace(/"/g, "&quot;")
    .replace(/'/g, "&apos;");
}

/**
 11  * @function unescapeHTML 还原html脚本 < > & " '
 12  * @param a -
 13  *            字符串
 14  */
function unescapeHTML(a) {
  a = "" + a;
  return a
    .replace(/&lt;/g, "<")
    .replace(/&gt;/g, ">")
    .replace(/&amp;/g, "&")
    .replace(/&quot;/g, '"')
    .replace(/&apos;/g, "'");
}

let json = {};

try {
  json = JSON.parse(readFileSync(`${path.resolve()}/package.json`, "utf8"));
} catch (e) {}

export const pkg = json;
